package entries;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ArrayList;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Models.Recipe;

public class BasicList extends JPanel {

	
	public static final String[] titles = {"ID:", "Name:", "Style:", "OG:", "FG:", "IBU:", "Pre Boil Vol(gal):", "Post Boil Vol(gal):",
			"Boil Time:", "Mash Temp(F):", "Mash Time:", "Efficiency:", "Brew Date:"};

	ArrayList<JLabel> titleLbls;
	ArrayList<JTextField> entriesTxt; //TODO REMOVE
	
	
	/**
	 * Contains all of the basic data about a recipe
	 * @param mode
	 */
	public BasicList(boolean mode) {
		this.setLayout(new GridBagLayout());
		titleLbls = new ArrayList<JLabel>();
		entriesTxt = new ArrayList<JTextField>();
		initializeComponents(mode);
	}
	
	/**
	 * Create all of the JLabels and JTextFields that are needed for displaying the
	 * basics of the recipe.
	 * @param mode
	 */
	private void initializeComponents(boolean mode) {
		for(int i = 0; i < titles.length; i++) {
			JLabel ttl = new JLabel(titles[i]);
			ttl.setAlignmentX(LEFT_ALIGNMENT);
			GridBagConstraints gbcTitle = new GridBagConstraints();
			gbcTitle.anchor = GridBagConstraints.WEST;
			gbcTitle.insets = new Insets(0,0,0,5);
			gbcTitle.weightx = 1;
			gbcTitle.gridx = 0;
			gbcTitle.gridy = i;
			this.add(ttl, gbcTitle);
			titleLbls.add(ttl);
			
			JTextField contents = new JTextField();
			contents.setPreferredSize(new Dimension(150,30));
			contents.setAlignmentX(LEFT_ALIGNMENT);
			contents.setEnabled(mode);
			if(i == 0) contents.setEnabled(false);  //turn off the id field
			GridBagConstraints gbcCont = new GridBagConstraints();
			gbcCont.anchor = GridBagConstraints.WEST;
			gbcCont.insets = new Insets(0,0,0,5);
			gbcCont.weightx = 1;
			gbcCont.gridx = 1;
			gbcCont.gridy = i;
			this.add(contents, gbcCont);
			entriesTxt.add(contents);
		}
	}
	
	
	/**
	 * sets the contents  of the JTextFields to contain the correct info about the recipe.
	 * @param contents
	 */
	public void updateContents(Recipe rec) {
		this.entriesTxt.get(0).setText(rec.getIdRecipe());
		this.entriesTxt.get(1).setText(rec.getName());
		this.entriesTxt.get(2).setText(rec.getStyle());
		this.entriesTxt.get(3).setText(rec.getOG());
		this.entriesTxt.get(4).setText(rec.getFG());
		this.entriesTxt.get(5).setText(rec.getIBU());
		this.entriesTxt.get(6).setText(rec.getPreBoilVol());
		this.entriesTxt.get(7).setText(rec.getPostBoilVol());
		this.entriesTxt.get(8).setText(rec.getBoilTime());
		this.entriesTxt.get(9).setText(rec.getMashTemp());
		this.entriesTxt.get(10).setText(rec.getMashTime());
		this.entriesTxt.get(11).setText(rec.getEfficiency());
		this.entriesTxt.get(12).setText(rec.getBrewDate());
	}
	
	
}

